﻿using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp.Demos.Coroutine
{
    public class Action02 : ICoroutineTask
    {
        public IEnumerator<Task> GetTasks()
        {
            // 这一行代码
            // 在调用 GetTasks() 方法时，就会执行
            Console.WriteLine($"{DateTime.Now} Action 2 - 开始执行 Action Baidu");

            yield return new HttpClient().GetAsync("https://www.baidu.com");
            Console.WriteLine($"{DateTime.Now} Action 2 - 结束执行 Action Baidu");
            Console.WriteLine($"{DateTime.Now} Action 2 - Do Delay Begin");
            yield return Task.Delay(1000);
            Console.WriteLine($"{DateTime.Now} Action 2 - Do Delay End");
            Console.WriteLine($"{DateTime.Now} Action 2 - 开始执行 Action Taobao");
            yield return new HttpClient().GetAsync("https://www.taobao.com");
            Console.WriteLine($"{DateTime.Now} Action 2 - 结束执行 Action Taobao");
        }
    }
}
